import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { CommService } from './../../comm/comm.service';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Rx';
import { ReportUrls } from '../../comm/report.urls.conf';
import { SubArea } from '../../model/report/sub-area';
import { QueryModel } from '../../model/report/query-model';
declare const $: any;
import { TVResource } from 'app/ptpmc/model/comm/tv-resource';
import { DxDataGridComponent } from '../../../../../node_modules/devextreme-angular';
import { Sc } from 'app/ptpmc/model/report/sc';
import { DxDropDownBoxComponent } from 'devextreme-angular';
import * as Enumerable from 'linq';
import * as ganttCharts from 'assets/visavail/js/ganttCharts.js';
import { FileUploader } from 'ng2-file-upload';
import { UserModel } from '../../../ptpmc/model/sys/user-model';
declare var laydate: any;
@Component({
    selector: 'app-sc',
    templateUrl: './sc.component.html',
    styleUrls: ['./sc.component.css'],
})

export class ScComponent implements OnInit, AfterViewInit {

    @ViewChild(DxDataGridComponent) dataGrid: DxDataGridComponent;
    //弹出框
    private dialogGrid: Sc = new Sc();
    private dialogInsert: Sc = new Sc();
    private cacelModel: Sc = new Sc();
    /*表示设置目标值的Dialog是否打开*/
    public opened = false;
    /**选择项 */
    public items: Sc[] = [];
    public selectedItems: Sc[] = [];
    title = '全业务链';
    public scListUrl: any[];
    public chartGanttOpt;
    public echartsInstance;
    public curItem;
    categories = [];
    types = [
    ];
    /*生产线 - 班次*/
    public subAreaItems: SubArea[];
    public shiftItems: any[];
    public equipmentItems: TVResource[] = [];
    public compareEquipmentSelected: TVResource[] = [];
    public subAareSelected: any;
    public shiftSelected: any;
    public equipmentSelected: TVResource;
    public _equipmentSelected: TVResource[] = [];
    /*报表下拉框*/
    public categoryItems: any[];
    public categorySelected: any;
    public inputSourceItems: any[];
    public inputSourceSelected: any;
    public safetyItems: any[];
    public safetySelected: any;
    public qualityItems: any[];
    public qualitySelected: any;
    public productItems: any[];
    public productSelected: any;
    public isDoItems: any[];
    public isDoSelected: any;
    public curStatusItems: any[];
    public curStatusSelected: any;
    public safetyAItems: any[];
    public safetyASelected: any;
    public qualityAItems: any[];
    public qualityASelected: any;
    public productAItems: any[];
    public productASelected: any;
    public changePointItems: any[];
    public changePointSelected: any;
    public chainId: any;
    public doTimePs: any;
    public groupList: any[];
    public listCharts: any[];
    public scChartOption: any;
    public classifyChartOption: any;
    public inputChartOption: any;
    public tmscListUrl: any[];
    public listChartsTM: any[];
    public pscListUrl: any[];
    public pwscListUrl: any[];
    public listChartsP: any[];
    public listChartsPW: any[];
    public modalType = 1;
    public modalTitle = '';
    public userList: any[];
    public userItems: any[];
    public searchUserStr = '';
    public userSelected: any[];
    public demandSelected: any[];
    public curUserName = UserModel.userName;
    //TD
    filterVlaueItems: string[] = ['All'];
    addFilterVlaueItemItem(data) {
        var newItem = data.text;
        this.filterVlaueItems.push(newItem)
        return newItem;
    }
    filterChange(data) {
        if (data.value == "All") {
            this.dataGrid.instance.clearFilter();
        } else {
            this.dataGrid.instance.filter(["duration", ">", data.value]);
        }
    }

    constructor(private commServices: CommService) {
    }
    onSubAreaSelectedChange(): void {
        this.equipmentItems = this.commServices.getTVResourceBySubArea(this.subAareSelected.subArea);
        this._equipmentSelected = this.equipmentItems;

    }
    get selectedRows(): TVResource[] {
        return this._equipmentSelected;
    }
    set selectedRows(value: TVResource[]) {
        this._equipmentSelected = value || [];
    }
    ngOnInit() {


        laydate.render({
            elem: '#dateTimeRangeP'
            , type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#dateTimeRangeS'
            , type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#dateTimeRangeStartInsert'
            , type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#dateTimeRangeEndInsert'
            , type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#dateTimeRangeEndActual'
            , type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#dateTimeRangeEndActualInsert'
            , type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#planedCompletionTimeA'
            //, type: 'time'
            , btns: ['confirm']
        });
        laydate.render({
            elem: '#planedCompletionTimeAInsert'
            //, type: 'time'
            , btns: ['confirm']
        });
        this.commServices.initDatePicker($('#DateTimeRange'), 'YYYY-MM-DD');
        this.commServices.initDatePicker2($('#dateTimeRangePlan'), 'YYYY-MM-DD', true);
        this.commServices.initDatePicker2($('#dateTimeRangePlanInsert'), 'YYYY-MM-DD', true);
        //this.commServices.initDatePicker2($('#dateTimeRangeS'), 'HH:mm:ss', true);
        //this.commServices.initDatePicker2($('#dateTimeRangeP'), 'HH:mm:ss', true);
        // this.commServices.initDatePicker2($('#dateTimeRangeStartInsert'), 'HH:mm:ss', true);
        // this.commServices.initDatePicker2($('#dateTimeRangeEndInsert'), 'HH:mm:ss', true);
        //this.commServices.initDatePicker2($('#dateTimeRangeEndActual'), 'HH:mm:ss', true);
        this.shiftItems = this.commServices.shifts;
        this.shiftSelected = this.shiftItems[0];
        this.subAreaItems = this.commServices.getSubAreas();
        this.subAareSelected = this.subAreaItems[0];
        this.equipmentItems = this.commServices.getTVResourceBySubArea(this.subAreaItems[0].subArea);
        this.equipmentSelected = this.equipmentItems[0];
        this.categoryItems = this.category;
        this.categorySelected = this.categoryItems[0];
        this.inputSourceItems = this.inputSource;
        this.inputSourceSelected = this.inputSourceItems[0];
        this.safetyItems = this.safety;
        this.safetySelected = this.safetyItems[0];
        this.qualityItems = this.quality;
        this.qualitySelected = this.qualityItems[0];
        this.productItems = this.product;
        this.productSelected = this.productItems[0];
        this.isDoItems = this.isDo;
        this.isDoSelected = this.isDoItems[0];
        this.curStatusItems = this.curStatus;
        this.curStatusSelected = this.curStatusItems[0];
        this.safetyAItems = this.safetyA;
        this.safetyASelected = this.safetyAItems[0];
        this.qualityAItems = this.qualityA;
        this.qualityASelected = this.qualityAItems[0];
        this.productAItems = this.productA;
        this.productASelected = this.productAItems[0];
        this.changePointItems = this.changePoint;
        this.changePointSelected = this.changePointItems[0];
        this.userSelected = new Array();
        this.demandSelected = new Array();
        this.getReportData();
        this.getReportDataPW();
        this.getAllUser();

    }

    ngAfterViewInit() {
    }
    public curStatus: Array<{ curStatusId: string, curStatusName: string }> = [
        //{ curStatusId: 'N/A', curStatusName: 'N/A' },
        { curStatusId: '1/4', curStatusName: '1/4' },
        { curStatusId: '2/4', curStatusName: '2/4' },
        { curStatusId: '3/4', curStatusName: '3/4' },
        { curStatusId: '4/4', curStatusName: '4/4' },
    ];
    public category: Array<{ categoryId: string, categoryName: string }> = [
        { categoryId: 'PM', categoryName: 'PM' },
        { categoryId: 'OM', categoryName: 'OM' },
        { categoryId: 'CM', categoryName: 'CM' },
        { categoryId: 'CIP', categoryName: 'CIP' },
    ];
    public safety: Array<{ safetyId: string, safetyName: string }> = [
        { safetyId: '需验证', safetyName: '需验证' },
        { safetyId: 'OK', safetyName: 'OK' },
        { safetyId: 'NOK', safetyName: 'NOK' },
    ];
    public quality: Array<{ qualityId: string, qualityName: string }> = [
        { qualityId: '需验证', qualityName: '需验证' },
        { qualityId: 'OK', qualityName: 'OK' },
        { qualityId: 'NOK', qualityName: 'NOK' },
    ];
    public product: Array<{ productId: string, productName: string }> = [
        { productId: '需验证', productName: '需验证' },
        { productId: 'OK', productName: 'OK' },
        { productId: 'NOK', productName: 'NOK' },
    ];
    public inputSource: Array<{ inputSourceId: string, inputSourceName: string }> = [
        { inputSourceId: '生产', inputSourceName: '生产' },
        { inputSourceId: '维修', inputSourceName: '维修' },
        { inputSourceId: '刀具', inputSourceName: '刀具' },
        { inputSourceId: '化学品', inputSourceName: '化学品' },
        { inputSourceId: 'PME', inputSourceName: 'PME' },
        { inputSourceId: 'PTQ', inputSourceName: 'PTQ' },
        { inputSourceId: 'SQE', inputSourceName: 'SQE' },
        { inputSourceId: 'PC&L', inputSourceName: 'PC&L' },
        { inputSourceId: '施工', inputSourceName: '施工' },
        { inputSourceId: 'IT', inputSourceName: 'IT' },
    ];

    public safetyA: Array<{ safetyAId: string, safetyAName: string }> = [
        { safetyAId: 'N/A', safetyAName: 'N/A' },
        { safetyAId: '需验证', safetyAName: '需验证' },
        { safetyAId: 'NOK', safetyAName: 'NOK' },
        { safetyAId: 'OK', safetyAName: 'OK' },
    ];
    public qualityA: Array<{ qualityAId: string, qualityAName: string }> = [
        { qualityAId: 'N/A', qualityAName: 'N/A' },
        { qualityAId: '需验证', qualityAName: '需验证' },
        { qualityAId: 'NOK', qualityAName: 'NOK' },
        { qualityAId: 'OK', qualityAName: 'OK' },
    ];
    public productA: Array<{ productAId: string, productAName: string }> = [
        { productAId: 'N/A', productAName: 'N/A' },
        { productAId: '需验证', productAName: '需验证' },
        { productAId: 'NOK', productAName: 'NOK' },
        { productAId: 'OK', productAName: 'OK' },
    ];
    public changePoint: Array<{ changePointId: string, changePointName: string }> = [
        { changePointId: '是', changePointName: '是' },
        { changePointId: '否', changePointName: '否' },
    ];
    public isDo: Array<{ isDoId: string, isDoName: string }> = [
        { isDoId: '进行中', isDoName: '进行中' },
        { isDoId: '完成', isDoName: '完成' },
        { isDoId: '延期', isDoName: '延期' },
        { isDoId: '失败', isDoName: '失败' },
    ];
    // downloadTemplate() {
    //     window.open(ReportUrls.BaseUrl + ReportUrls.ToolTemplateUrl);
    // }
    /**获取表格数据*/
    getReportData(): void {
        debugger
        const queryModel: QueryModel = new QueryModel();
        queryModel.dateTimeRange = this.getTime('DateTimeRange');
        queryModel.querySubAreaIds = [this.subAareSelected.subArea];
        const url: string = ReportUrls.ScListUrl;
        this.commServices
            .getList(queryModel, url)
            .subscribe(model => {
                if (model.resultCode === 200) {
                    debugger
                    this.scListUrl = model.data;
                    this.listCharts = this.scListUrl;
                    this.showCharts(true);
                    this.showClassifyChart();
                    this.showInputChart();
                } else {
                    console.log(model.resultCode + ',' + model.resultMessage);
                }
            });
    }
    /**
   * 获取表格数据
   */
    getReportDataTM(): void {

        const queryModel: QueryModel = new QueryModel();
        queryModel.dateTimeRange = this.getTime('DateTimeRange');
        queryModel.querySubAreaIds = [this.subAareSelected.subArea];
        const url: string = ReportUrls.TMScListUrl;
        this.commServices
            .getList(queryModel, url)
            .subscribe(model => {
                if (model.resultCode === 200) {
                    this.tmscListUrl = model.data;
                    this.listChartsTM = this.tmscListUrl;
                } else {
                    console.log(model.resultCode + ',' + model.resultMessage);
                }
            });
    }
    /**
* 获取表格数据
*/
    getReportDataP(itemData: Sc): void {
        this.curItem = itemData;
        const queryModel: QueryModel = new QueryModel();
        // queryModel.dateTimeRange = this.getTime('DateTimeRange');
        queryModel.querySubAreaIds = [this.subAareSelected.subArea];
        queryModel.dateTimeRange = itemData.doTimeP;
        queryModel.compareTimeRange1 = itemData.responsePersonA;
        this.dialogGrid.doTimeP = itemData.doTimeP;
        this.dialogGrid.responsePersonA = itemData.responsePersonA;
        const url: string = ReportUrls.PScListUrl;
        this.commServices
            .getList(queryModel, url)
            .subscribe(model => {
                if (model.resultCode === 200) {
                    debugger
                    this.pscListUrl = model.data;
                    this.listChartsP = this.pscListUrl;
                    if (this.itemDetailDate) {
                        const i = this.pscListUrl.find(item=>item.chainId == this.itemDetailDate.chainId);
                        
                        this.dialogGrid.eleQuantityP = i.eleQuantityP;
                    }
                    this.initChartOpt(this.pscListUrl);
                } else {
                    console.log(model.resultCode + ',' + model.resultMessage);
                }
            });
    }
    getReportDataPW(): void {
        //this.curItem = itemData;
        const queryModel: QueryModel = new QueryModel();
        // queryModel.dateTimeRange = this.getTime('DateTimeRange');
        queryModel.querySubAreaIds = [this.subAareSelected.subArea];
        queryModel.dateTimeRange = this.dialogGrid.doTimeP;
        // queryModel.compareTimeRange1 = itemData.responsePersonA;
        // this.dialogGrid.doTimeP = itemData.doTimeP;
        // this.dialogGrid.responsePersonA = itemData.responsePersonA;
        const url: string = ReportUrls.PWScListUrl;
        
        this.commServices
            .getList(queryModel, url)
            .subscribe(model => {
                if (model.resultCode === 200) {
                    
                    this.pwscListUrl = model.data;
                    this.listChartsPW = this.pwscListUrl;
                } else {
                    console.log(model.resultCode + ',' + model.resultMessage);
                }
            });
    }
    exportTemplate() {
        const files = new Array<any>();
        const queryModelArray = new Array<any>();
        queryModelArray.push('时间:' + this.getTime('DateTimeRange'));
        queryModelArray.push('区域:' + this.subAareSelected.subArea);
        this.chartsMap.forEach((v, k) => {
            if (k !== 'Gantt') {
                const picBase64Info = v.getDataURL();
                if (k == '全业务链生产线维护各功能块实施状态') {
                    files.push({ chartsTitle: k, chartsEncodeStr: picBase64Info, nextNewPage: 2 });
                } else {
                    files.push({ chartsTitle: k, chartsEncodeStr: picBase64Info });
                }

            }
        });

        const tables = new Array<any>();

        const rows = new Array();
        // const r = new Array();
        // r.push("状态");
        // r.push("次数");
        // r.push("百分比");
        // r.push("OM");
        // r.push("PM");
        // r.push("CM");
        // r.push("CIP");
        // r.push("生产");
        // r.push("维修");
        // r.push("刀具");
        // r.push("化学品");
        // r.push("PME");
        // r.push("PTQ");
        // r.push("SQE");
        // r.push("PC&L");
        // r.push("施工");
        // r.push("IT");
        // rows.push(r);
        this.groupList.forEach(item => {
            const r = new Array();
            r.push(item.curStatusA);
            r.push(item.curStatusATimes);
            r.push(item.percent);
            r.push(item.om);
            r.push(item.pm);
            r.push(item.cm);
            r.push(item.cip);
            r.push(item.sc);
            r.push(item.wx);
            r.push(item.dj);
            r.push(item.hx);
            r.push(item.pme);
            r.push(item.ptq);
            r.push(item.sqe);
            r.push(item.pcl);
            r.push(item.sg);
            r.push(item.it);
            rows.push(r);
        })

        const table1 = {
            //tableName: '全业务链统计图表',
            titles: ["状态", "次数", "百分比", "OM", "PM", "CM", "CIP", "生产", "维修", "刀具", "化学品", "PME", "PTQ", "SQE", "PC&L", "施工", "IT"],
            rows: rows,
            nextNewPage: 2
        };

        tables.push(table1);

       
        const upload = {
            //reportTitle: '全业务链统计图表',
            charts: files,
            queryModel: queryModelArray,
            tables: tables
        };

        this.commServices.exportPdf(upload);
    }

    showCharts(reviewCharts: boolean) {
        const sumTime = this.listCharts.length;
        this.groupList = Enumerable.from(this.listCharts).groupBy(u => u.curStatusA).select(u => {
            const temp = {
                curStatusA: u.first().curStatusA,
                curStatusATimes: u.count(),
                percent: ((u.count() / sumTime) * 100).toFixed(2)
            };
            return temp;
        }).orderBy(u => u.curStatusA).toArray();
        if (reviewCharts) {
            const x1 = new Array();
            const y1 = new Array();
            const yBar = new Array();
            this.groupList.forEach((e: { curStatusATimes, curStatusA, project }) => {
                x1.push(e.curStatusA);
                const bean1 = { value: e.curStatusATimes, name: e.curStatusA + '次数：' + e.curStatusATimes };
                y1.push(bean1);
                yBar.push(e.curStatusA);

            });

            if (this.groupList.length < 4) {
                const temp = [0, 0, 0, 0];
                this.groupList.forEach(item => {
                    if (item.curStatusA == '1/4') {
                        temp[0] = 1;
                    } else if (item.curStatusA == '2/4') {
                        temp[1] = 1;
                    } else if (item.curStatusA == '3/4') {
                        temp[2] = 1;
                    } else if (item.curStatusA == '4/4') {
                        temp[3] = 1;
                    }
                })

                const t: any = new Object();
                for (let i = 0; i < temp.length; i++) {
                    if (temp[i] == 0) {
                        if (i == 0) {
                            t.curStatusA = '1/4';
                        } else if (i == 1) {
                            t.curStatusA = '2/4';
                        } else if (i == 2) {
                            t.curStatusA = '3/4';
                        } else if (i == 3) {
                            t.curStatusA = '4/4';
                        }
                    }
                }

                const g = this.groupList[0];
                for (let i in g) {
                    t.i = 0;
                }
                t.curStatusATimes = 0;
                t.percent = 0;
                this.groupList.push(t);
            }

            this.groupList = Enumerable.from(this.groupList).orderBy(e => e.curStatusA).toArray();

            this.scChartOption = this.getOption(x1, y1, 'pie');
        }

    }
    getOption(x: any, y: any, type: String): any {

        const option = {
            title: {
                text: '',
                subtext: '',
                x: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: (p) => {
                    return '状态: ' + p.name + '  占比:' + p.percent + '%' + '<br/>';
                },
            },
            toolbox: {
                show: true,
                feature: {
                    // dataView : {show: true, readOnly: false},
                    // magicType : {show: true, type: ['line', 'bar']},
                    // restore : {show: true},
                    saveAsImage: { show: true }
                }
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: x
            },
            series: [
                {
                    name: '全业务链生产线维护总体实施状态',
                    type: type,
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: y,
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ],
            color: ['#CD5C5C', '#FFD700', '#1E90FF', '#32CD32'],
        };

        return option;
    }

    typesMap = new Map<string, number>();
    // 甘特图
    initChartOpt(pscListUrl) {
        const data = [];
        this.categories = []
        let min = 0;
        let max;
        this.typesMap.clear();
        pscListUrl.forEach(e => {
            if (!this.typesMap.has(e.stationP)) {
                this.typesMap.set(e.stationP, 0);
                this.categories.push(e.stationP);

            }

            const caterotyIndex = this.categories.findIndex(el => el === e.stationP);
            if (min === 0) {
                min = e.workTimeStartPT;
            } else {
                min = Math.min(min, e.workTimeStartPT);
            }
            max = Math.max(max, e.workTimeEndPT);
            //this.categories.sort();
            // 计算空闲时间段
            data.push({
                name: e.stationP,
                value: [
                    caterotyIndex,
                    e.workTimeStartPT,
                    e.workTimeEndPT,
                    (e.workTimeEndPT - e.workTimeStartPT) / 60000,  // 持续时间
                    e.workContentP
                ],
                itemStyle: {
                    normal: {
                        color: '#0f0'
                    }
                }
            });
        });
        this.chartGanttOpt = ganttCharts.ganttEchartsQ('全业务链维护甘特图表', this.echartsInstance, this.categories, this.types, data, min, 'hh');
    }
    // initWd(){
    //     WdatePicker({skin:'whyGreen',dateFmt:'H:mm:ss'});
    //    
    // }
    //柱状图1
    private showClassifyChart(): void {
        const r1 = [0, 0, 0, 0];  //1/4  'OM','PM','CM','CIP'
        const r2 = [0, 0, 0, 0];
        const r3 = [0, 0, 0, 0];
        const r4 = [0, 0, 0, 0];
        const R1_4OM: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.categoryP === 'OM');
        const R1_4PM: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.categoryP === 'PM');
        const R1_4CM: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.categoryP === 'CM');
        const R1_4CIP: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.categoryP === 'CIP');

        if (this.groupList.find(e => e.curStatusA === '1/4')) {
            this.groupList.find(e => e.curStatusA === '1/4')['om'] = R1_4OM.length;
            this.groupList.find(e => e.curStatusA === '1/4')['pm'] = R1_4PM.length;
            this.groupList.find(e => e.curStatusA === '1/4')['cm'] = R1_4CM.length;
            this.groupList.find(e => e.curStatusA === '1/4')['cip'] = R1_4CIP.length;
        }

        if (R1_4OM) {
            r1[0] = R1_4OM.length;
        }
        if (R1_4PM) {
            r1[1] = R1_4PM.length;
        }
        if (R1_4CM) {
            r1[2] = R1_4CM.length;
        }
        if (R1_4CIP) {
            r1[3] = R1_4CIP.length;
        }
        const R2_4OM: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.categoryP === 'OM');
        const R2_4PM: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.categoryP === 'PM');
        const R2_4CM: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.categoryP === 'CM');
        const R2_4CIP: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.categoryP === 'CIP');

        if (this.groupList.find(e => e.curStatusA === '2/4')) {
            this.groupList.find(e => e.curStatusA === '2/4')['om'] = R2_4OM.length;
            this.groupList.find(e => e.curStatusA === '2/4')['pm'] = R2_4PM.length;
            this.groupList.find(e => e.curStatusA === '2/4')['cm'] = R2_4CM.length;
            this.groupList.find(e => e.curStatusA === '2/4')['cip'] = R2_4CIP.length;
        }

        if (R2_4OM) {
            r2[0] = R2_4OM.length;
        }
        if (R2_4PM) {
            r2[1] = R2_4PM.length;
        }
        if (R2_4CM) {
            r2[2] = R2_4CM.length;
        }
        if (R2_4CIP) {
            r2[3] = R2_4CIP.length;
        }
        const R3_4OM: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.categoryP === 'OM');
        const R3_4PM: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.categoryP === 'PM');
        const R3_4CM: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.categoryP === 'CM');
        const R3_4CIP: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.categoryP === 'CIP');
        if (this.groupList.find(e => e.curStatusA === '3/4')) {
            this.groupList.find(e => e.curStatusA === '3/4')['om'] = R3_4OM.length;
            this.groupList.find(e => e.curStatusA === '3/4')['pm'] = R3_4PM.length;
            this.groupList.find(e => e.curStatusA === '3/4')['cm'] = R3_4CM.length;
            this.groupList.find(e => e.curStatusA === '3/4')['cip'] = R3_4CIP.length;
        }

        if (R3_4OM) {
            r3[0] = R3_4OM.length;
        }
        if (R3_4PM) {
            r3[1] = R3_4PM.length;
        }
        if (R3_4CM) {
            r3[2] = R3_4CM.length;
        }
        if (R3_4CIP) {
            r3[3] = R3_4CIP.length;
        }
        const R4_4OM: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.categoryP === 'OM');
        const R4_4PM: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.categoryP === 'PM');
        const R4_4CM: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.categoryP === 'CM');
        const R4_4CIP: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.categoryP === 'CIP');
        if (this.groupList.find(e => e.curStatusA === '4/4')) {
            this.groupList.find(e => e.curStatusA === '4/4')['om'] = R4_4OM.length;
            this.groupList.find(e => e.curStatusA === '4/4')['pm'] = R4_4PM.length;
            this.groupList.find(e => e.curStatusA === '4/4')['cm'] = R4_4CM.length;
            this.groupList.find(e => e.curStatusA === '4/4')['cip'] = R4_4CIP.length;
        }

        if (R4_4OM) {
            r4[0] = R4_4OM.length;
        }
        if (R3_4PM) {
            r4[1] = R4_4PM.length;
        }
        if (R3_4CM) {
            r4[2] = R4_4CM.length;
        }
        if (R3_4CIP) {
            r4[3] = R4_4CIP.length;
        }


        this.classifyChartOption = {
            tooltip: {

                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            toolbox: {
                show: true,
                feature: {
                    // dataView : {show: true, readOnly: false},
                    // magicType : {show: true, type: ['line', 'bar']},
                    // restore : {show: true},
                    saveAsImage: { show: true }
                }
            },
            legend: {
                data: ['1/4', '2/4', '3/4', '4/4']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['OM', 'PM', 'CM', 'CIP']
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '1/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r1
                },
                {
                    name: '2/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r2
                },
                {
                    name: '3/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r3
                },

                {
                    name: '4/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r4
                },
            ],
            color: ['#CD5C5C', '#FFD700', '#1E90FF', '#32CD32'],
        };
        // this.showloading = false;
    }
    //柱状图2
    private showInputChart(): void {
        const r1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];  //1/4  '生产','维修','刀具','化学品','PME','PTQ','SQE','PC&L','施工','IT'
        const r2 = [0, 0, 0, 0, 0, 0, 0, 0, 0,];
        const r3 = [0, 0, 0, 0, 0, 0, 0, 0, 0,];
        const r4 = [0, 0, 0, 0, 0, 0, 0, 0, 0,];
        const R1_4SC: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === '生产');
        const R1_4WX: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === '维修');
        const R1_4DJ: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === '刀具');
        const R1_4HX: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === '化学品');
        const R1_4PME: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === 'PME');
        const R1_4PTQ: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === 'PTQ');
        const R1_4SQE: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === 'SQE');
        const R1_4PCL: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === 'PC&L');
        const R1_4SG: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === '施工');
        const R1_4IT: Array<any> = this.listCharts.filter(e => e.curStatusA === '1/4' && e.inputSourceP === 'IT');
        if (this.groupList.find(e => e.curStatusA === '1/4')) {
            this.groupList.find(e => e.curStatusA === '1/4')['sc'] = R1_4SC.length;
            this.groupList.find(e => e.curStatusA === '1/4')['wx'] = R1_4WX.length;
            this.groupList.find(e => e.curStatusA === '1/4')['dj'] = R1_4DJ.length;
            this.groupList.find(e => e.curStatusA === '1/4')['hx'] = R1_4HX.length;
            this.groupList.find(e => e.curStatusA === '1/4')['pme'] = R1_4PME.length;
            this.groupList.find(e => e.curStatusA === '1/4')['ptq'] = R1_4PTQ.length;
            this.groupList.find(e => e.curStatusA === '1/4')['sqe'] = R1_4SQE.length;
            this.groupList.find(e => e.curStatusA === '1/4')['pcl'] = R1_4PCL.length;
            this.groupList.find(e => e.curStatusA === '1/4')['sg'] = R1_4SG.length;
            this.groupList.find(e => e.curStatusA === '1/4')['it'] = R1_4IT.length;
        }

        if (R1_4SC) {
            r1[0] = R1_4SC.length;
        }
        if (R1_4WX) {
            r1[1] = R1_4WX.length;
        }
        if (R1_4DJ) {
            r1[2] = R1_4DJ.length;
        }
        if (R1_4HX) {
            r1[3] = R1_4HX.length;
        }
        if (R1_4PME) {
            r1[4] = R1_4PME.length;
        }
        if (R1_4PTQ) {
            r1[5] = R1_4PTQ.length;
        }
        if (R1_4SQE) {
            r1[6] = R1_4SQE.length;
        }
        if (R1_4PCL) {
            r1[7] = R1_4PCL.length;
        }
        if (R1_4SG) {
            r1[8] = R1_4SG.length;
        }
        if (R1_4IT) {
            r1[9] = R1_4IT.length;
        }
        const R2_4SC: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === '生产');
        const R2_4WX: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === '维修');
        const R2_4DJ: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === '刀具');
        const R2_4HX: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === '化学品');
        const R2_4PME: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === 'PME');
        const R2_4PTQ: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === 'PTQ');
        const R2_4SQE: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === 'SQE');
        const R2_4PCL: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === 'PC&L');
        const R2_4SG: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === '施工');
        const R2_4IT: Array<any> = this.listCharts.filter(e => e.curStatusA === '2/4' && e.inputSourceP === 'IT');
        if (this.groupList.find(e => e.curStatusA === '2/4')) {
            this.groupList.find(e => e.curStatusA === '2/4')['sc'] = R2_4SC.length;
            this.groupList.find(e => e.curStatusA === '2/4')['wx'] = R2_4WX.length;
            this.groupList.find(e => e.curStatusA === '2/4')['dj'] = R2_4DJ.length;
            this.groupList.find(e => e.curStatusA === '2/4')['hx'] = R2_4HX.length;
            this.groupList.find(e => e.curStatusA === '2/4')['pme'] = R2_4PME.length;
            this.groupList.find(e => e.curStatusA === '2/4')['ptq'] = R2_4PTQ.length;
            this.groupList.find(e => e.curStatusA === '2/4')['sqe'] = R2_4SQE.length;
            this.groupList.find(e => e.curStatusA === '2/4')['pcl'] = R2_4PCL.length;
            this.groupList.find(e => e.curStatusA === '2/4')['sg'] = R2_4SG.length;
            this.groupList.find(e => e.curStatusA === '2/4')['it'] = R2_4IT.length;
        }

        if (R2_4SC) {
            r2[0] = R2_4SC.length;
        }
        if (R2_4WX) {
            r2[1] = R2_4WX.length;
        }
        if (R2_4DJ) {
            r2[2] = R2_4DJ.length;
        }
        if (R2_4HX) {
            r2[3] = R2_4HX.length;
        }
        if (R2_4PME) {
            r2[4] = R2_4PME.length;
        }
        if (R2_4PTQ) {
            r2[5] = R2_4PTQ.length;
        }
        if (R2_4SQE) {
            r2[6] = R2_4SQE.length;
        }
        if (R2_4PCL) {
            r2[7] = R2_4PCL.length;
        }
        if (R2_4SG) {
            r2[8] = R2_4SG.length;
        }
        if (R2_4IT) {
            r2[9] = R2_4IT.length;
        }
        const R3_4SC: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === '生产');
        const R3_4WX: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === '维修');
        const R3_4DJ: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === '刀具');
        const R3_4HX: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === '化学品');
        const R3_4PME: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === 'PME');
        const R3_4PTQ: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === 'PTQ');
        const R3_4SQE: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === 'SQE');
        const R3_4PCL: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === 'PC&L');
        const R3_4SG: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === '施工');
        const R3_4IT: Array<any> = this.listCharts.filter(e => e.curStatusA === '3/4' && e.inputSourceP === 'IT');
        if (this.groupList.find(e => e.curStatusA === '3/4')) {
            this.groupList.find(e => e.curStatusA === '3/4')['sc'] = R3_4SC.length;
            this.groupList.find(e => e.curStatusA === '3/4')['wx'] = R3_4WX.length;
            this.groupList.find(e => e.curStatusA === '3/4')['dj'] = R3_4DJ.length;
            this.groupList.find(e => e.curStatusA === '3/4')['hx'] = R3_4HX.length;
            this.groupList.find(e => e.curStatusA === '3/4')['pme'] = R3_4PME.length;
            this.groupList.find(e => e.curStatusA === '3/4')['ptq'] = R3_4PTQ.length;
            this.groupList.find(e => e.curStatusA === '3/4')['sqe'] = R3_4SQE.length;
            this.groupList.find(e => e.curStatusA === '3/4')['pcl'] = R3_4PCL.length;
            this.groupList.find(e => e.curStatusA === '3/4')['sg'] = R3_4SG.length;
            this.groupList.find(e => e.curStatusA === '3/4')['it'] = R3_4IT.length;
        }

        if (R3_4SC) {
            r3[0] = R3_4SC.length;
        }
        if (R3_4WX) {
            r3[1] = R3_4WX.length;
        }
        if (R3_4DJ) {
            r3[2] = R3_4DJ.length;
        }
        if (R3_4HX) {
            r3[3] = R3_4HX.length;
        }
        if (R3_4PME) {
            r3[4] = R3_4PME.length;
        }
        if (R3_4PTQ) {
            r3[5] = R3_4PTQ.length;
        }
        if (R3_4SQE) {
            r3[6] = R3_4SQE.length;
        }
        if (R3_4PCL) {
            r3[7] = R3_4PCL.length;
        }
        if (R3_4SG) {
            r3[8] = R3_4SG.length;
        }
        if (R3_4IT) {
            r3[9] = R3_4IT.length;
        }
        const R4_4SC: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === '生产');
        const R4_4WX: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === '维修');
        const R4_4DJ: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === '刀具');
        const R4_4HX: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === '化学品');
        const R4_4PME: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === 'PME');
        const R4_4PTQ: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === 'PTQ');
        const R4_4SQE: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === 'SQE');
        const R4_4PCL: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === 'PC&L');
        const R4_4SG: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === '施工');
        const R4_4IT: Array<any> = this.listCharts.filter(e => e.curStatusA === '4/4' && e.inputSourceP === 'IT');
        if (this.groupList.find(e => e.curStatusA === '4/4')) {
            this.groupList.find(e => e.curStatusA === '4/4')['sc'] = R4_4SC.length;
            this.groupList.find(e => e.curStatusA === '4/4')['wx'] = R4_4WX.length;
            this.groupList.find(e => e.curStatusA === '4/4')['dj'] = R4_4DJ.length;
            this.groupList.find(e => e.curStatusA === '4/4')['hx'] = R4_4HX.length;
            this.groupList.find(e => e.curStatusA === '4/4')['pme'] = R4_4PME.length;
            this.groupList.find(e => e.curStatusA === '4/4')['ptq'] = R4_4PTQ.length;
            this.groupList.find(e => e.curStatusA === '4/4')['sqe'] = R4_4SQE.length;
            this.groupList.find(e => e.curStatusA === '4/4')['pcl'] = R4_4PCL.length;
            this.groupList.find(e => e.curStatusA === '4/4')['sg'] = R4_4SG.length;
            this.groupList.find(e => e.curStatusA === '4/4')['it'] = R4_4IT.length;
        }

        if (R4_4SC) {
            r4[0] = R4_4SC.length;
        }
        if (R4_4WX) {
            r4[1] = R4_4WX.length;
        }
        if (R4_4DJ) {
            r4[2] = R4_4DJ.length;
        }
        if (R4_4HX) {
            r4[3] = R4_4HX.length;
        }
        if (R4_4PME) {
            r4[4] = R4_4PME.length;
        }
        if (R4_4PTQ) {
            r4[5] = R4_4PTQ.length;
        }
        if (R4_4SQE) {
            r4[6] = R4_4SQE.length;
        }
        if (R4_4PCL) {
            r4[7] = R4_4PCL.length;
        }
        if (R4_4SG) {
            r4[8] = R4_4SG.length;
        }
        if (R4_4IT) {
            r4[9] = R4_4IT.length;
        }


        this.inputChartOption = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                },
            },
            toolbox: {
                show: true,
                feature: {
                    // dataView : {show: true, readOnly: false},
                    // magicType : {show: true, type: ['line', 'bar']},
                    // restore : {show: true},
                    saveAsImage: { show: true }
                }
            },
            legend: {
                data: ['1/4', '2/4', '3/4', '4/4']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['生产', '维修', '刀具', '化学品', 'PME', 'PTQ', 'SQE', 'PC&L', '施工', 'IT']
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '1/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r1
                },
                {
                    name: '2/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r2
                },
                {
                    name: '3/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r3
                },

                {
                    name: '4/4',
                    type: 'bar',
                    stack: 'OM',
                    data: r4
                },
            ],
            color: ['#CD5C5C', '#FFD700', '#1E90FF', '#32CD32'],
        };
        ;
        // this.showloading = false;
    }
    /**ECharts图表相关*/
    chartsMap = new Map<any, any>();
    onChartInit(index: any, echartsIntance: any): void {
        this.chartsMap.set(index, echartsIntance);
        Observable.fromEvent(window, 'resize')
            .debounceTime(100) // 以免频繁处理
            .subscribe(() => this.echartsInstance.resize());
    }
    public updateFilterList: Sc[] = [];
    addData() {
        const addModel: any = new Sc();
        addModel.subArea = this.subAareSelected.subArea;
        addModel.categoryP = this.categorySelected.categoryName;
        addModel.inputSourceP = this.inputSourceSelected.inputSourceName;
        addModel.stationP = this.equipmentSelected.equipment;
        addModel.workContentP = this.dialogInsert.workContentP;
        addModel.safetyP = this.safetySelected.safetyName;
        addModel.qualityP = this.qualitySelected.qualityName;
        addModel.productP = this.productSelected.productName;
        addModel.isDoP = this.isDoSelected.isDoName;
        addModel.planeP = this.dialogInsert.planeP;
        addModel.doTimeP = this.dialogGrid.doTimeP;
        const at = this.getTime('dateTimeRangeStartInsert');
        if (at !== '') {
            addModel.workTimeStartP1 = this.dialogGrid.doTimeP + ' ' + this.getTime('dateTimeRangeStartInsert');
        } else {
            addModel.workTimeStartP1 = this.dialogGrid.doTimeP + ' ' + '00:00:00.000'
        }
        if (this.getTime('dateTimeRangeEndInsert') !== '') {
            //if(this.getTime('dateTimeRangeEndInsert') > at){
            addModel.workTimeEndP1 = this.dialogGrid.doTimeP + ' ' + this.getTime('dateTimeRangeEndInsert');
            // }else{
            //     alert('结束时间不能早于开始时间');
            // }

        } else {
            addModel.workTimeEndP1 = this.dialogGrid.doTimeP + ' ' + '00:00:00.000'
        }
        addModel.desiredEffectP = this.dialogInsert.desiredEffectP;
        addModel.resultD = this.dialogInsert.resultD;
        addModel.changePointD = this.changePointSelected.changePointName;
        addModel.ppcrD = this.dialogInsert.ppcrD;
        addModel.resultVerifierC = this.dialogInsert.resultVerifierC;
        addModel.moC = this.dialogInsert.moC;
        addModel.ptqC = this.dialogInsert.ptqC;
        addModel.safetyA = this.safetyASelected.safetyAName;
        addModel.qualityA = this.qualityASelected.qualityAName;
        addModel.productA = this.productASelected.productAName;
        addModel.resultD = this.dialogInsert.resultD;
        addModel.riskControlMeasuresA = this.dialogInsert.riskControlMeasuresA;
        addModel.workContentA = this.dialogInsert.workContentA;
        addModel.responsePersonA = this.dialogInsert.responsePersonA;
        addModel.trackPersonA = this.dialogInsert.trackPersonA;
        //if (this.getTime('planedCompletionTimeAInsert') !== '') {
        addModel.planedCompletionTimeA = this.getTime('planedCompletionTimeAInsert');
        // } else {
        //     addModel.planedCompletionTimeA1 = this.dialogGrid.doTimeP + ' ' + '00:00:00.000'
        // }
        addModel.curStatusA = this.curStatusSelected.curStatusName;
        addModel.needP = this.dialogInsert.needP;
        addModel.executorP = this.dialogInsert.executorP;
        if (this.getTime('dateTimeRangeEndActualInsert') !== '') {
            addModel.actualTimeEndD1 = this.dialogGrid.doTimeP + ' ' + this.getTime('dateTimeRangeEndActualInsert');
        } else {
            addModel.actualTimeEndD1 = this.dialogGrid.doTimeP + ' ' + ' ' + '00:00:00.000'
        }
        const url: string = ReportUrls.ScAddUrl;
        this.commServices
            .doPost(url, addModel)
            .subscribe(model => {
                this.items = [];
                if (model.resultCode === 200) {
                    this.items = model.data;
                    this.getReportDataTM();
                    this.getReportDataP(this.curItem);
                } else {
                    console.log(model.resultCode + ',' + model.resultMessage);
                }
            });
        $('#InsertModal').modal('toggle');
    }

    saveChanges() {
        debugger
        try {
            const updateModel: any = new Sc();
            updateModel.subArea = this.subAareSelected.subArea;
            updateModel.chainId = this.chainId;
            updateModel.categoryP = this.categorySelected.categoryName;
            updateModel.inputSourceP = this.inputSourceSelected.inputSourceName;
            updateModel.stationP = this.equipmentSelected.equipment;
            updateModel.workContentP = this.dialogGrid.workContentP;
            // if(this.safetySelected.safetyName == null){
            //     updateModel.safetyP = '需验证'
            // }else{
                updateModel.safetyP = this.safetySelected.safetyName;
            //}
            
            updateModel.qualityP = this.qualitySelected.qualityName;
            updateModel.productP = this.productSelected.productName;
            updateModel.isDoP = this.isDoSelected.isDoName;
            updateModel.planeP = this.dialogGrid.planeP;
            updateModel.eleTimeP = this.dialogGrid.eleTimeP;
            updateModel.doTimeP = this.dialogGrid.doTimeP;
            if(this.getTime('dateTimeRangeS')==''){
                updateModel.workTimeStartP1 = this.dialogGrid.doTimeP + ' ' +'00:00:00'
            }else{
                updateModel.workTimeStartP1 = this.dialogGrid.doTimeP + ' ' + this.getTime('dateTimeRangeS');
            }
            if(this.getTime('dateTimeRangeP')==''){
                updateModel.workTimeEndP1 = this.dialogGrid.doTimeP + ' ' + '00:00:00';
            }else{
                updateModel.workTimeEndP1 = this.dialogGrid.doTimeP + ' ' + this.getTime('dateTimeRangeP');
            }
           
            updateModel.desiredEffectP = this.dialogGrid.desiredEffectP;
            updateModel.resultD = this.dialogGrid.resultD;
            updateModel.changePointD = this.changePointSelected.changePointName;
            updateModel.ppcrD = this.dialogGrid.ppcrD;
            updateModel.resultVerifierC = this.dialogGrid.resultVerifierC;
            updateModel.moC = this.dialogGrid.moC;
            updateModel.ptqC = this.dialogGrid.ptqC;
            updateModel.safetyA = this.safetyASelected.safetyAName;
            updateModel.qualityA = this.qualityASelected.qualityAName;
            updateModel.productA = this.productASelected.productAName;
            updateModel.resultD = this.dialogGrid.resultD;
            updateModel.riskControlMeasuresA = this.dialogGrid.riskControlMeasuresA;
            updateModel.workContentA = this.dialogGrid.workContentA;
            updateModel.responsePersonA = this.dialogGrid.responsePersonA;
            updateModel.trackPersonA = this.dialogGrid.trackPersonA;
            updateModel.planedCompletionTimeA = this.getTime('planedCompletionTimeA');
            //updateModel.planedCompletionTimeA = this.dialogGrid.planedCompletionTimeA;
            updateModel.curStatusA = this.curStatusSelected.curStatusName;
            updateModel.needP = this.dialogGrid.needP;
            updateModel.executorP = this.dialogGrid.executorP;
            debugger
            if(this.getTime('dateTimeRangeEndActual') == ''){
                updateModel.actualTimeEndD1 = this.dialogGrid.doTimeP + ' ' + '00:00:00';
            }else{
                updateModel.actualTimeEndD1 = this.dialogGrid.doTimeP + ' ' + this.getTime('dateTimeRangeEndActual');
            }
           debugger
            this.commServices.update(updateModel, ReportUrls.ScUpdateUrl)
                .subscribe(model => {
                    if (model.resultCode === 200) {
                        this.updateFilterList = [];
                        alert('更新成功！');
                        this.getReportData();
                        this.getReportDataTM();
                        this.getReportDataP(this.curItem);
                    } else {
                        // console.log(model.resultCode + ',' + model.resultMessage);
                        alert('更新失败！' + model.resultMessage);
                    }
                });
            //$("#filterModal").modal('toggle');
        } catch (e) {
            alert('请填写正确的参数');
        }
        $('#filterModal').modal('toggle');
    }

    saveChangesW(itemData: Sc) {
        debugger
        if (confirm('是否加入')) {
            this.chainId = itemData.chainId;
            const updateModel: any = new Sc();
            updateModel.chainId = this.chainId;
            updateModel.subArea = this.subAareSelected.subArea;
            updateModel.responsePersonA = this.userSelected.map(e => e.email).join(',');
            updateModel.doTimePs = itemData.doTimeP;
            updateModel.doTimeP = this.dialogGrid.doTimeP;
            updateModel.workTimeStartP1 = this.dialogGrid.doTimeP + ' ' + itemData.workTimeStartP;
            updateModel.workTimeEndP1 = this.dialogGrid.doTimeP + ' ' + itemData.workTimeEndP;
            this.commServices.update(updateModel, ReportUrls.ScUpdateWUrl)
                .subscribe(model => {
                    if (model.resultCode === 200) {
                        debugger
                        this.updateFilterList = [];
                        alert('加入成功！');
                        this.getReportDataPW();
                        this.getReportDataTM();
                        this.getReportDataP(this.curItem);
                    } else {
                        // console.log(model.resultCode + ',' + model.resultMessage);
                        alert('加入失败！' + model.resultMessage);
                    }
                });
        }
    }


    cancelPlan(itemData: Sc) {
        //if (confirm('是否取消计划'))
        this.chainId = itemData.chainId;
        const updateModel: any = new Sc();
        updateModel.chainId = this.chainId;
        updateModel.inputSourceP = itemData.inputSourceP;
        updateModel.stationP = itemData.stationP;
        updateModel.workContentP = itemData.workContentP;
        updateModel.responsePersonA = this.userSelected.map(e => e.email).join(',');
        updateModel.subArea = this.subAareSelected.subArea;
        updateModel.curUserName = this.curUserName;
        //updateModel.doTimeP = this.dialogGrid.doTimeP;
        this.commServices.update(updateModel, ReportUrls.ScUpdateQUrl)
            .subscribe(model => {
                if (model.resultCode === 200) {
                    this.updateFilterList = [];
                    alert('取消成功！');
                    this.getReportDataTM();
                    this.getReportDataPW();
                    // this.getReportDataP(this.curItem);
                } else {
                    // console.log(model.resultCode + ',' + model.resultMessage);
                    alert('取消失败！' + model.resultMessage);
                }
            });
        // }
        $('#CacelModal').modal('toggle');
    }
    getAllUser() {

        this.commServices.getList({}, ReportUrls.AllUser).subscribe(modle => {
            if (modle.resultCode === 200) {
                modle.data.allUser = modle.data.allUser.filter(e => e.name !== '');
                this.userList = modle.data.allUser;
                this.userItems = modle.data.allUser;

            } else {
                console.log(modle.resultCode + ',' + modle.resultMessage);
            }
        });
    }
    /**获取TimeRange的值*/
    getTime(id: any): String {
        const timerange: String = $('#' + id).val();
        return timerange;
    }
    /**
     * 下载Excel模板
     */
    downloadTemplate() {
        window.open(ReportUrls.BaseUrl + ReportUrls.ScTempExport);
    }

    //excel 文件导入
    public uploader: FileUploader = new FileUploader({
        url: ReportUrls.BaseUrl + ReportUrls.ScImport,
        method: 'POST',
        autoUpload: false,
        itemAlias: 'uploader',
    });
    /**
     * 导入数据
     */
    importExcel() {
        debugger

        this.uploader.queue[0].onSuccess = function (response, status) {
            debugger
            if (status === 200) {
                debugger
                // 上传文件后获取服务器返回的数据
                // let res = JSON.parse(response);
                alert('上传成功');
            } else {
                // 上传文件后获取服务器返回的数据错误
                alert('上传失败');
            }
        };
        this.uploader.queue[0].upload(); // 开始上传   
        // 上传
        // this.uploader.queue[0].onSuccess = (response, status, headers) => {
        //     debugger
        //     // 上传文件成功
        //     if (status === 200) {
        //         debugger
        //         // 上传文件后获取服务器返回的数据
        //         const res = JSON.parse(response);
        //         if (res.resultCode === 200) {
        //             // this.getReportDataPW();
        //             // this.getReportDataP(this.curItem);
        //             alert('导入数据成功！');
        //         } else {
        //             alert('数据导入出错！');
        //         }
        //         // this.uploader.queue = [];
        //         // this.uploader.clearQueue();
        //     } else {
        //         // 上传文件后获取服务器返回的数据错误
        //         alert('数据导入失败');
        //     }
        // };
        // this.uploader.setOptions({ additionalParameter: this.equipmentSelected });
        // this.uploader.queue[0].upload(); // 开始上传   

    }
    itemDetailDate;
    /**Dialog相关*/
    openDialog(itemData: Sc): void {
        this.itemDetailDate = itemData;
        this.chainId = itemData.chainId;
        this.dialogGrid = itemData;
        // this.dialogGrid.planedCompletionTimeA = itemData.planedCompletionTimeA;
        this.dialogGrid.workTimeStartP = itemData.workTimeStartP;
        this.dialogGrid.workTimeEndP = itemData.workTimeEndP;
        this.categorySelected = this.categoryItems.find(e => e.categoryName === itemData.categoryP);
        this.inputSourceSelected = this.inputSourceItems.find(e => e.inputSourceName === itemData.inputSourceP);
        this.equipmentSelected = this.equipmentItems.find(e => e.equipment === itemData.stationP);
        this.safetySelected = this.safetyItems.find(e => e.safetyName === itemData.safetyP);
        this.qualitySelected = this.qualityItems.find(e => e.qualityName === itemData.qualityP);
        this.productSelected = this.productItems.find(e => e.productName === itemData.productP);
        this.isDoSelected = this.isDoItems.find(e => e.isDoName === itemData.isDoP);
        this.dialogGrid.eleQuantityP = itemData.eleQuantityP;
        this.changePointSelected = this.changePointItems.find(e => e.changePointName === itemData.changePointD);
        this.safetyASelected = this.safetyAItems.find(e => e.safetyAName === itemData.safetyA);
        this.qualityASelected = this.qualityAItems.find(e => e.qualityAName === itemData.qualityA);
        this.productASelected = this.productAItems.find(e => e.productAName === itemData.productA);
        this.curStatusSelected = this.curStatusItems.find(e => e.curStatusName === itemData.curStatusA);
        $('#filterModal').modal('toggle');
    }
    openInsertDialog(): void {
        this.dialogInsert = new Sc;
        this.categorySelected = '';
        this.inputSourceSelected = '';
        this.equipmentSelected = null;
        $('#InsertModal').modal('toggle');

        this.getReportDataPW();
    }
    openInsertDialogT(itemData: Sc): void {
        this.dialogGrid = itemData;
        $('#filterModalT').modal('toggle');
    }
    openCacelDialog(itemData: Sc): void {
        this.cacelModel = itemData;

        $('#CacelModal').modal('toggle');
    }
    // delpdf(itemData: Sc) {
    //     if (confirm('是否删除')) {
    //         this.commServices.delete(itemData, ReportUrls.ToolDeleteUrl).subscribe(model => {
    //             if (model.resultCode === 200) {
    //                 // this.getReportDataPW();
    //                 // this.getReportDataP(this.curItem);
    //             } else {
    //                 // console.log(model.resultCode + ',' + model.resultMessage);
    //                 //alert('下载失败！' + model.resultMessage);
    //             }
    //         });
    //     }
    // }

    @ViewChild('dddbCompare') dddbCompare: DxDropDownBoxComponent
    clearCompareEquipmentSelected() {
        this.compareEquipmentSelected = [];
    }
    compareEquipmentSelectedOk() {
        this.dddbCompare.instance.close();
    }


    searchUser() {
        if (this.searchUserStr == '') {
            this.userList = this.userItems;
        } else {
            this.userList = this.userList.filter(e => e.loginName.indexOf(this.searchUserStr) !== -1);
        }

    }

    addEmailUser(user) {
        if (this.modalType == 1) {
            if (this.userSelected.find(e => e.email == user.email) !== undefined) {
                this.userSelected = this.userSelected.filter(e => e.email !== user.email)
            } else {
                this.userSelected.push(user);
            }
        } else {
            if (this.demandSelected.find(e => e.email == user.email) !== undefined) {
                this.demandSelected = this.demandSelected.filter(e => e.email !== user.email)
            } else {
                this.demandSelected.push(user);
            }
        }
    }

    userIsSelected(user) {

        if (this.modalType == 1) {
            return this.userSelected.find(e => e.email == user.email) !== undefined;
        } else {
            return this.demandSelected.find(e => e.email == user.email) !== undefined;
        }
    }


    addUser(type) {
        this.modalType = type;
        $('#userModal').modal('toggle');
        if (type == 1) {
            this.modalTitle = '选择责任人';
        } else {
            this.modalTitle = '选择需求人';
        }
    }

    userStr(type): string {
        return type === 1 ? this.userSelected.map(e => e.name).join(', ') : this.demandSelected.map(e => e.name).join(', ');
    }
    onExporting(e) {
        e.fileName = e.fileName + new Date().toISOString().replace(/[\-\:\.]/g, '').split('T')[0];
    }
}
